#!/bin/sh
HTMLFILE=$1
CSSNAME=$2


sed -r "s:(<link[^>]*)/>:\\1></link>:" -i "$1"
sed "s: *></link>:></link>:" -i "$1"

sed -r "s:<link[^>]*type=\"text/css\"[^>]*href=['\"]$2['\"]></link>:\n<style type=\"text/css\">\n###\n</style>:" -i "$1"
#sed -r "s:(<script.*)src=['\"]$2['\"].*</script>:\\1>\n###\n</script>\n:" -i "$1"

cat $1 | grep "###" -B 999999 | grep -v "###" > before.tmp
cat $1 | grep "###" -A 999999 | grep -v "###" > after.tmp
(cat before.tmp; cat "$2"; cat after.tmp) > newhtml.tmp
rm before.tmp after.tmp
mv newhtml.tmp "$1"
